home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / misc / NVX_timeul2.lha / C_Source.lha / GUI_temp.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  7KB  |  354 lines

  1. ;/* GUI_temp - Execute me to compile me with Lattice.
  2. LC -b0 -cfistq -v -y GUI_temp.c
  3. Blink with Make
  4. quit
  5. */
  6.  
  7. /* This file contains empty template routines that
  8.  * the IDCMP handler will call uppon. Fill out these
  9.  * routines with your code or use them as a reference
  10.  * to create your program.
  11.  */
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/classes.h>
  16. #include <intuition/classusr.h>
  17. #include <intuition/imageclass.h>
  18. #include <intuition/gadgetclass.h>
  19. #include <libraries/gadtools.h>
  20. #include <libraries/AmigaGuide.h>
  21. #include <graphics/displayinfo.h>
  22. #include <graphics/gfxbase.h>
  23. #include <libraries/asl.h>
  24. #include <workbench/startup.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/intuition_protos.h>
  28. #include <clib/gadtools_protos.h>
  29. #include <clib/graphics_protos.h>
  30. #include <clib/utility_protos.h>
  31. #include <clib/asl_protos.h>
  32. #include <clib/amigaguide_protos.h>
  33. #include <string.h>
  34. #include "stdlib.h"
  35. #include "stdio.h"
  36.  
  37. #include "GUI.h"
  38.  
  39. void FixString( char *from, char *to, int length);
  40.  
  41. extern struct Library *AmigaGuideBase;
  42. extern struct FileRequester *OurFReq;
  43. extern struct List *SelFiles;
  44. extern LONG TotalK, Rate, Rates[];
  45. extern char ptrn[];
  46.  
  47. int selected=0;
  48. char Entry[100];
  49. char FName[22];
  50.  
  51. struct Node *AddANodeAlpha( struct List *list, char *Name );
  52. void ClearList( struct List *Start );
  53. BOOL FindNodeA( struct Node *Start, char *String, struct Node **Insert );
  54. struct Node *FindOrd( struct List *list, UWORD ordinal );
  55. WORD OrdNode( struct Node *node );
  56. void RemoveANode( struct Node *Bye );
  57. APTR Allocvec( ULONG size, LONG type );
  58. void Freevec( APTR addr );
  59.  
  60. BOOL TFReq( char *title);
  61.  
  62. void UpdateDL( void );
  63.  
  64. int Gadget00Clicked( void )
  65. {
  66.     /* routine when gadget ListView"" is clicked. */
  67.  
  68. selected = MarksMsg.Code;    /* Save ID of selected entry */
  69.  
  70. return 1;
  71. }
  72.  
  73. int Gadget10Clicked( void )
  74. {
  75.  
  76. /* routine when gadget MX"" is clicked. */
  77.  
  78. Rate = Rates[ MarksMsg.Code ];
  79.  
  80. /* Update the CPS gadget */
  81. GT_SetGadgetAttrs( MarksGadgets[8], MarksWnd, NULL, GTNM_Number, Rate, TAG_END );
  82.  
  83. /* Update d'l size and time */
  84. UpdateDL();
  85.  
  86. return 1;
  87. }
  88.  
  89. int Gadget30Clicked( void )
  90. {
  91.     /* routine when gadget "_Add" is clicked. */
  92.  
  93. struct FileLock *lock;
  94. struct FileHandle *handle;
  95. struct WBArg *files;
  96.  
  97. LONG size;
  98. int temp;
  99.  
  100. /* Display the ASL requester .. */
  101. if( AslRequestTags( OurFReq,ASLFR_InitialPattern, &ptrn[0],
  102.                         ASLFR_DoMultiSelect,
  103.                         ASLFR_DoPatterns,
  104.                         ASLFR_Flags1, FRF_DOPATTERNS,
  105.                         ASLFR_Flags1, FRF_DOMULTISELECT,
  106.                         TAG_DONE ) )
  107.     {
  108.     files = OurFReq->fr_ArgList;
  109.  
  110.     if( lock=(struct FileLock *)Lock( OurFReq->fr_Drawer, ACCESS_READ ) )
  111.         {
  112.         /* CD to selected drawer */
  113.         lock = (struct FileLock *)CurrentDir( (BPTR)lock );
  114.  
  115.         /* Step through the list of selected files */
  116.         for(temp=0; temp<OurFReq->fr_NumArgs ; temp++)
  117.             {
  118.             /* Determine the length of the file */
  119.             if ( handle = ( struct FileHandle *) Open( files->wa_Name, MODE_OLDFILE) )
  120.                 {
  121.                 Seek( (BPTR)handle, 0, OFFSET_END );
  122.                 size=Seek((BPTR)handle, 0, OFFSET_BEGINNING );
  123.                 TotalK += size;
  124.                 Close( (BPTR)handle );
  125.                 }
  126.  
  127.             /* Make text for entry */
  128.             FixString( files->wa_Name, FName, 20);
  129.             sprintf( Entry, "%20s %7d", FName, size );
  130.  
  131.             /* Freeze List View */
  132.             GT_SetGadgetAttrs(MarksGadgets[0],MarksWnd,NULL,GTLV_Labels,-1,TAG_END);
  133.  
  134.             /* Add text to list */
  135.             AddANodeAlpha( SelFiles, Entry );
  136.  
  137.             /* Update List View */
  138.             GT_SetGadgetAttrs( MarksGadgets[0], MarksWnd, NULL, GTLV_Labels, SelFiles, TAG_END );
  139.  
  140.             /* Update d'l size and time */
  141.             UpdateDL();
  142.  
  143.             /* Step to next selected file */
  144.             files++;
  145.             }
  146.         
  147.         /* CD back to our original drawer and free the lock */
  148.         lock=(struct FileLock *)CurrentDir( (BPTR)lock );
  149.         UnLock( (BPTR)lock );
  150.         }
  151.  
  152.     }
  153.  
  154. return 1;
  155. }
  156.  
  157. int Gadget40Clicked( void )
  158. {
  159.     /* routine when gadget "_Delete" is clicked. */
  160. int l;
  161.  
  162. struct Node *node;
  163.  
  164. /* Freeze List View */
  165. GT_SetGadgetAttrs( MarksGadgets[0], MarksWnd, NULL, GTLV_Labels, -1, TAG_END );
  166.  
  167. /* Remove Node */
  168.  
  169. if( node= FindOrd( SelFiles, selected ) )
  170.     {
  171.     l=atoi( (node->ln_Name)+20 );
  172.     TotalK -= l;
  173.     RemoveANode( node );
  174.     
  175.     /* Update d'l size and time */
  176.     UpdateDL();
  177.     
  178.     if(!FindOrd( SelFiles, selected ) )
  179.         if( selected ) selected--;
  180.     }
  181.  
  182. /* Update List View */
  183. GT_SetGadgetAttrs( MarksGadgets[0], MarksWnd, NULL, GTLV_Labels, SelFiles, TAG_END );
  184.  
  185. return 1;
  186. }
  187.  
  188. int Gadget50Clicked( void )
  189. {
  190.     /* routine when gadget "_Clear" is clicked. */
  191.  
  192. /* Freeze List View */
  193. GT_SetGadgetAttrs( MarksGadgets[0], MarksWnd, NULL, GTLV_Labels, -1, TAG_END );
  194.  
  195. /* Clear the list */
  196. ClearList( SelFiles );
  197.  
  198. TotalK=0;
  199.  
  200. sprintf( Entry, " %02d:%02d:%02d", 0, 0, 0 );
  201. GT_SetGadgetAttrs( MarksGadgets[2], MarksWnd, NULL, GTTX_Text, Entry, TAG_END );
  202.  
  203. sprintf( Entry, " %d bytes", TotalK );
  204. GT_SetGadgetAttrs( MarksGadgets[7], MarksWnd, NULL, GTTX_Text, Entry, TAG_END );
  205.  
  206. /* Update List View */
  207. GT_SetGadgetAttrs( MarksGadgets[0], MarksWnd, NULL, GTLV_Labels, SelFiles, TAG_END );
  208.  
  209. return 1;
  210. }
  211.  
  212. int Gadget60Clicked( void )
  213. {
  214.     /* routine when gadget "About" is clicked. */
  215. int m;
  216.  
  217. if ( !OpenProject1Window() )
  218.     {
  219.     m=1;
  220.     while (m) m=HandleProject1IDCMP();
  221.     CloseProject1Window();
  222.     }
  223.  
  224. return 1;
  225. }
  226.  
  227. int Gadget90Clicked( void )
  228. {
  229.     /* routine when gadget "_Help" is clicked. */
  230.  
  231. struct NewAmigaGuide nag = {NULL};
  232. AMIGAGUIDECONTEXT handle;
  233. LONG retval = 0L;
  234.  
  235. if( AmigaGuideBase )
  236.     {
  237.     /* Fill in the NewAmigaGuide structure */
  238.     nag.nag_Name = "TimeUL.Guide";
  239.     nag.nag_Node = NULL;
  240.     nag.nag_Line = 0;
  241.  
  242.     /* Open the AmigaGuide client */
  243.     if ( handle = OpenAmigaGuide(&nag, NULL))
  244.         CloseAmigaGuide(handle);
  245.     else
  246.         OkReq( "Error opening 'TimeUL.Guide'!" );
  247.     }
  248. else
  249.     OkReq( "Error: No 'amigaguide.library'!" );
  250.  
  251. return 1;
  252. }
  253.  
  254. int Gadget01Clicked( void )
  255. {
  256.     /* routine when gadget "That's Just Dandy!" is clicked. */
  257. return 0;
  258. }
  259.  
  260. int MarksCloseWindow( void )
  261. {
  262.     /* routine for "IDCMP_CLOSEWINDOW". */
  263.  
  264. return TFReq( "Really Quit :-(" );
  265. /*return 0;*/
  266. }
  267.  
  268. int MarksVanillaKey( void )
  269. {
  270.     /* routine for "IDCMP_VANILLAKEY". */
  271.  
  272. switch( (char)MarksMsg.Code )
  273.     {
  274.     case 'A':
  275.     case 'a':
  276.         Gadget30Clicked();
  277.         break;
  278.     
  279.     case 'D':
  280.     case 'd':
  281.         Gadget40Clicked();
  282.         break;
  283.     
  284.     case 'C':
  285.     case 'c':
  286.         Gadget50Clicked();
  287.         break;
  288.  
  289.     case 'H':
  290.     case 'h':
  291.         Gadget90Clicked();
  292.         break;
  293.  
  294.     }
  295.  
  296. return 1;
  297. }
  298.  
  299. int Project1CloseWindow( void )
  300. {
  301.     /* routine for "IDCMP_CLOSEWINDOW". */
  302. return 0;
  303. }
  304.  
  305. /* Copies a string, either clipping it or expanding it to a defined width
  306.  
  307. Entry    *from    source string
  308.     *to    dest string
  309.     length    desired length of destination string
  310.  
  311. */
  312.  
  313. void FixString( char *from, char *to, int length)
  314. {
  315. int loop, plus;
  316. register int i;
  317.  
  318. loop=strlen( from );
  319.  
  320. if( loop > length )
  321.     {
  322.     loop=length;
  323.     plus=0;
  324.     }
  325. else
  326.     plus=length-loop;
  327.  
  328. for( i=0; i<loop; i++ )    *to++ = *from++;
  329.  
  330. if( plus )
  331.     for( i=0; i<plus; i++ ) *to++ = ' ';
  332.  
  333. *to = '\0';
  334.  
  335. }
  336.  
  337. void UpdateDL( void )
  338. {
  339. LONG TotalHr, TotalMin, TotalSec;
  340.  
  341. /* Determine time in Hr:Min:Sec  */
  342. TotalSec = TotalK/Rate;
  343. TotalHr = TotalSec/3600;
  344. TotalSec = TotalSec - TotalHr*3600;
  345. TotalMin = TotalSec/60;
  346. TotalSec = TotalSec - TotalMin*60;
  347.  
  348. sprintf( Entry, " %02d:%02d:%02d", TotalHr, TotalMin, TotalSec );
  349. GT_SetGadgetAttrs( MarksGadgets[2], MarksWnd, NULL, GTTX_Text, Entry, TAG_END );
  350.  
  351. sprintf( Entry, " %d bytes", TotalK );
  352. GT_SetGadgetAttrs( MarksGadgets[7], MarksWnd, NULL, GTTX_Text, Entry, TAG_END );
  353.  
  354. }